const { defineConfig } = require('@vue/cli-service')
const Mock = require('mockjs')
let { tab, tabList } = Mock.mock({
  'tab|10': [
    {
      img: '@image(50x50,@color,image)',
      title: '@ctitle(4)',
    },
  ],
  'tabList|10': [
    {
      id: '@id',
      src: '@image(180x120,@color,image)',
      title: '@ctitle(7)',
      word: '@cword(9)',
      'count|+1': 1,
    },
  ],
})
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    setupMiddlewares(mid, { app }) {
      app.get('/api/tab', (req, res) => {
        res.send({
          code: 200,
          tab,
        })
      })
      app.get('/api/tabList', (req, res) => {
        res.send({
          code: 200,
          tabList,
        })
      })
      app.get('/api/detail', (req, res) => {
        let { id } = req.query
        let item = tabList.find((item) => item.id === id)
        res.send({
          code: 200,
          item,
        })
      })
      return mid
    },
  },
})
